/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.opencvjava.piano;

import com.opencvjava.piano.support.Block;
import com.opencvjava.piano.support.ImageInfo;
import com.opencvjava.piano.support.Unit;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

import static com.opencvjava.piano.support.Unit.R;
import static com.opencvjava.support.util.CvUtils.imshow;

/**
 * @author : sunzb
 * @date: 2019/11/28
 */
@Service
public class Extract5 {
    Random random = new Random();
    public void test() {
        ImageInfo img = new ImageInfo("piano", "test.jpg").build();
        Mat src = img.getSrc();
        List<Unit> fillUnits = img.getFillBlock().getUnits();
        for (Unit unit : fillUnits) {
            Imgproc.rectangle(src, new Rect(unit.getColStart(), unit.getRowStart(), R, R),
                    new Scalar(255, 255, 255), -1);
        }
        /*for (Block block : img.getBlocks()) {
            int b = random.nextInt(256);
            int g = random.nextInt(256);
            int r = random.nextInt(256);
            for (Unit unit : block.getUnits()) {
                Imgproc.rectangle(src, new Rect(unit.getColStart(), unit.getRowStart(), R, R),
                        new Scalar(b, g, r), -1);
            }
        }*/
        imshow("fill block", src);
    }
}
